{
"cells": [
{
"cell_type": "markdown",
"id": "57a92274",
"metadata": {},
"source": [
"# **CAISO** - Load, Fuel Mix, and LMP Data\n",
"\n",
"This notebook walk through how to use `gridstatus` to access to the data availabe on [OASIS](http://oasis.caiso.com/).\n",
"\n",
"While we will be using CAISO in this example, but most of this API will also work with all other ISOs."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3599dfce",
"metadata": {},
"outputs": [],
"source": [
"import gridstatus\n",
"import pandas as pd\n",
"import plotly.express as px"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "854ac803",
"metadata": {},
"outputs": [],
"source": [
"caiso = gridstatus.CAISO()"
]
},
{
"cell_type": "markdown",
"id": "965746ab",
"metadata": {},
"source": [
"let's also define a method to make it easier to name our files"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "cb2926b6",
"metadata": {},
"outputs": [],
"source": [
"folder = \"../../../archived_iso_data/caiso/\"\n",
"def make_filename(name, start, end):\n",
" return f\"{name}_{start.strftime('%Y-%m-%d')}_{end.strftime('%Y-%m-%d')}.csv\" "
]
},
{
"cell_type": "markdown",
"id": "4612c2d0",
"metadata": {},
"source": [
"## Historical Fuel Mix"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d35b27ed",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1662/1662 [14:11<00:00, 1.95it/s]\n"
]
}
],
"source": [
"start = pd.Timestamp(\"April 10, 2018\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"mix_df = caiso.get_fuel_mix(start, end=end, verbose=False)\n",
"mix_df.to_csv(make_filename(folder+\"fuel_mix\", start, end), index=None)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a652e033",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": ""
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"monthly_mix = mix_df.set_index(\"Time\").resample(\"MS\").sum().reset_index()[1:-1]\n",
"fig = px.bar(monthly_mix, x=\"Time\", y=monthly_mix.columns[1:], title=\"Fuel Mix by Month - CAISO\")\n",
"fig.show(\"svg\")"
]
},
{
"cell_type": "markdown",
"id": "bb652292",
"metadata": {},
"source": [
"## Historical Load "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "27098731",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1662/1662 [11:33<00:00, 2.40it/s]\n"
]
}
],
"source": [
"start = pd.Timestamp(\"April 10, 2018\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"load_df = caiso.get_load(start, end=end, verbose=False)\n",
"\n",
"load_df.to_csv(make_filename(folder+\"load\", start, end), index=None)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "4eb4c3e3",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": ""
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"daily_load = load_df.set_index(\"Time\").resample(\"W\").sum().reset_index()[1:-1]\n",
"fig = px.line(daily_load, x=\"Time\", y=\"Load\", title=\"Weekly Load - CAISO\")\n",
"fig.show(\"svg\")"
]
},
{
"cell_type": "markdown",
"id": "7193787c",
"metadata": {},
"source": [
"## Historical Locational Marginal Pricing (LMP)\n",
"\n",
"You can supply whatever nodes or market you'd like, but for now let's download data for 3 trading hubs in the Day Head Hourly Market"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "86cb97a7",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 10/10 [03:56<00:00, 23.68s/it]\n"
]
}
],
"source": [
"start = pd.Timestamp(\"Jan 01, 2022\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"locations = ['TH_NP15_GEN-APND', 'TH_SP15_GEN-APND', 'TH_ZP26_GEN-APND']\n",
"\n",
"lmp_df = caiso.get_lmp(start=start, \n",
" end=end,\n",
" market='DAY_AHEAD_HOURLY', \n",
" locations=locations, \n",
" sleep=5)\n",
"\n",
"lmp_df.to_csv(make_filename(folder+\"dam_lmp\", start, end), index=None)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "39c891f9",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": ""
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"daily_lmp = lmp_df.set_index(\"Time\").groupby(\"Location\").resample(\"1D\").mean().reset_index()[1:-1]\n",
"fig = px.line(daily_lmp, x=\"Time\", y=\"LMP\", title=\"DAILY LMP - CAISO\", color=\"Location\")\n",
"fig.show(\"svg\")"
]
},
{
"cell_type": "markdown",
"id": "10f2ba2a",
"metadata": {},
"source": [
"## Gas Prices\n",
"\n",
"CAISO also publish information about gas prices and greenhouse gas allownces that we will download"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "917a3e07",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 10/10 [00:58<00:00, 5.81s/it]\n"
]
}
],
"source": [
"start = start = pd.Timestamp(\"Jan 01, 2022\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"gas_price_df = caiso.get_gas_prices(start=start, end=end, fuel_region_id=\"FRPGE2GHG\")\n",
"\n",
"gas_price_df.to_csv(make_filename(folder+\"gas_prices\", start, end), index=None)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "f4168867",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 10/10 [00:55<00:00, 5.52s/it]\n"
]
}
],
"source": [
"start = start = pd.Timestamp(\"Jan 01, 2022\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"ghg_df = caiso.get_ghg_allowance(start=start, end=end)\n",
"\n",
"ghg_df.to_csv(make_filename(folder+\"ghg_allowance\", start, end), index=None)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b9af602",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.2 64-bit ('gridstatus')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
},
"vscode": {
"interpreter": {
"hash": "49f14642123d0cc1afa9fa45716ed5f1e915189c28b01efe02a8b7ec3c0a3fce"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}